package practice抽奖箱;

import java.util.Random;

public class lotteryBox extends Thread{

    // 该成集合效果更好
    static int[] box = {10,5,20,50,100,200,500,800,2,80,300,700};
    static int count = box.length;

    static{
        Random random = new Random();
        for (int i = 0; i < box.length; i++) {
            int j = random.nextInt(5);
            int tmp = box[i];
            box[i] = box[j];
            box[j] = tmp;
        }
    }

    @Override
    public void run() {
        while(true){
            synchronized (lotteryBox.class){
                if(count == 0){
                    break;
                }else{
                    System.out.println(getName()+"又产生了一个"+box[count-1]+"元大奖");
                    count--;
                    Thread.yield();
                }
            }
        }
    }
}
